package com.rongshe.hotel.service.impl;

import java.util.List;

import com.rongshe.common.utils.DateUtils;
import com.rongshe.common.utils.StringUtils;
import com.rongshe.hotel.domain.RsStation;
import com.rongshe.hotel.mapper.RsStationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rongshe.hotel.mapper.RsBookingMapper;
import com.rongshe.hotel.domain.RsBooking;
import com.rongshe.hotel.service.IRsBookingService;

/**
 * 行程Service业务层处理
 *
 * @author rongshe
 * @date 2025-02-17
 */
@Service
public class RsBookingServiceImpl implements IRsBookingService {
    @Autowired
    private RsBookingMapper rsBookingMapper;

    @Autowired
    private RsStationMapper rsStationMapper;

    /**
     * 查询行程
     *
     * @param id 行程主键
     * @return 行程
     */
    @Override
    public RsBooking selectRsBookingById(Long id) {
        return rsBookingMapper.selectRsBookingById(id);
    }

    /**
     * 查询行程列表
     *
     * @param rsBooking 行程
     * @return 行程
     */
    @Override
    public List<RsBooking> selectRsBookingList(RsBooking rsBooking) {
        return rsBookingMapper.selectRsBookingList(rsBooking);
    }

    /**
     * 新增行程
     *
     * @param rsBooking 行程
     * @return 结果
     */
    @Override
    public int insertRsBooking(RsBooking rsBooking) {
        rsBooking.setCreateTime(DateUtils.getNowDate());
        RsStation rsStation = rsStationMapper.selectRsStationById(rsBooking.getStationId());
        rsBooking.setStationName(rsStation.getStationName());
        rsBooking.setUpdateTime(DateUtils.getNowDate());
        return rsBookingMapper.insertRsBooking(rsBooking);
    }

    /**
     * 修改行程
     *
     * @param rsBooking 行程
     * @return 结果
     */
    @Override
    public int updateRsBooking(RsBooking rsBooking) {
        rsBooking.setUpdateTime(DateUtils.getNowDate());
        if (StringUtils.isNotEmpty(rsBooking.getStatus())) {
            switch (rsBooking.getStatus()) {
                case "1":
                    RsStation rsStation = rsStationMapper.selectRsStationById(rsBooking.getStationId());
                    rsBooking.setStationName(rsStation.getStationName());
                    break;
                case "2":
                    if (null == rsBooking.getCompleteTime()) {
                        rsBooking.setCompleteTime(DateUtils.getNowDate());
                    }
                    break;
                case "3":
                    rsBooking.setCancelTime(DateUtils.getNowDate());
                    break;
                case "4":
                    if (null == rsBooking.getConfirmTime()) {
                        rsBooking.setConfirmTime(DateUtils.getNowDate());
                    }
                    break;
                case "5":
                    if (null == rsBooking.getDepartureTime()) {
                        rsBooking.setDepartureTime(DateUtils.getNowDate());
                    }

            }
        }
        return rsBookingMapper.updateRsBooking(rsBooking);
    }

    /**
     * 批量删除行程
     *
     * @param ids 需要删除的行程主键
     * @return 结果
     */
    @Override
    public int deleteRsBookingByIds(Long[] ids) {
        return rsBookingMapper.deleteRsBookingByIds(ids);
    }

    /**
     * 删除行程信息
     *
     * @param id 行程主键
     * @return 结果
     */
    @Override
    public int deleteRsBookingById(Long id) {
        return rsBookingMapper.deleteRsBookingById(id);
    }


}
